package com.aipanda.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * 广告位置类
 * @param name 			广告位置名称
 * @param width 		宽度
 * @param height 		高度
 * @param description  	描述
 * @param template 		模板
 * @param ads 			广告
 * @author wanyuxiang
 *
 */
@Entity
@Table(name = "aipanda_ad_position")
public class AdPosition extends BaseEntity {
	private static final long serialVersionUID = -7849848867030199578L;
	private String name;
	private Integer width;
	private Integer height;
	private String description;
	private String template;
	private Set<Ad> ads = new HashSet<Ad>();

	@NotEmpty
	@Length(max = 255)
	@Column(nullable = false)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@NotNull
	@Min(1L)
	@Column(nullable = false)
	public Integer getWidth() {
		return this.width;
	}

	public void setWidth(Integer width) {
		this.width = width;
	}

	@NotNull
	@Min(1L)
	@Column(nullable = false)
	public Integer getHeight() {
		return this.height;
	}

	public void setHeight(Integer height) {
		this.height = height;
	}

	@Length(max = 255)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@NotEmpty
	@Lob
	@Column(nullable = false)
	public String getTemplate() {
		return this.template;
	}

	public void setTemplate(String template) {
		this.template = template;
	}

	@OneToMany(mappedBy = "adPosition", fetch = FetchType.LAZY, cascade = {CascadeType.REMOVE})
	@OrderBy("order asc")
	public Set<Ad> getAds() {
		return this.ads;
	}

	public void setAds(Set<Ad> ads) {
		this.ads = ads;
	}
}
